// import axios from 'axios'
import { userUrl } from '@/public/uri.js'
// import qs from "qs";
export default {
    getSsData({ commit }, data) {
        axios.get(`${userUrl}/userdata/getssdata`, {
            params: {
                userName: data
            }
        }).then(
            res => {
                if (res.data.ok === 1) {
                    commit('setSsData', res.data.data)
                }
            }
        ).catch()
    },

    getAllSsData({ commit }, data) { // 获取热门的说说数据        
        axios.get(`${userUrl}/alldata/getallssdata`, {
            params: data
        }).then(res => {
            if (res.data.ok === 1) {
                commit('setAllSsData', res.data)
            }
        })
    },





    getRzData({ commit }, data) { // 获取用户的日志数据
        axios.get(`${userUrl}/userdata/getrzdata`, {
            params: {
                userName: data
            }
        }).then(res => {
            if (res.data.ok) {
                commit('setRzData', res.data.data)
            }
        })
    },



    getAllRzData({ commit }, data) { // 获取热门的日志数据
        axios.get(`${userUrl}/alldata/getAllRzdata`, {
            params: data
        }).then(res => {
            if (res.data.ok) {
                commit('setAllRzData', res.data)
            }
        })
    },


    getAlbumsData({ commit }, data) {
        axios.get(`${userUrl}/userdata/getalbums`, {
            params: {
                userName: data
            }
        }).then(res => {
            if (res.data.ok === 1) {

                commit('setAlbumsData', res.data.data)
            }
        }).catch(err => {
            console.log("错误信息:" + err);
        });
    },

    getUserInfoData({ commit }, userName) {
        axios.get(`${userUrl}/userdata/getuserdata`, {
            params: {
                userName: userName
            }
        }).then(res => {
            if (res.data.ok === 1) {
                commit('setUserInfoData', res.data.data)
            } else {
                commit('setUserInfoData', {})
            }
        }).catch(err => {
            console.log("错误提示：" + err);
        });
    },


    async setUserInfoData(ctx, data) {
        return await axios.post(`${userUrl}/userdata/setuserdata`, data)
    },



    getUserPhotosData({ commit }, data) {
        axios.get(`${userUrl}/userdata/getalbumphotosdata`, {
            params: {
                name: data
            }
        }).then(res => {
            if (res.data.ok === 1) {
                commit('setUserPhotosData', res.data.data)
            }
        }).catch(err => {
            console.log("错误提示：" + err);
        });
    },



    getVideosData({ commit }, data) {
        axios.get(`${userUrl}/userdata/getvideos`, {
            params: {
                userName: data
            }
        }).then(res => {
            if (res.data.ok === 1) {
                commit('setvideosData', res.data.data)
            }
        }).catch(err => {
            console.log("错误信息:" + err);
        });
    },


    getUserVideoData({ commit }, data) {
        axios.get(`${userUrl}/userdata/getvideosvideodata`, {
            params: {
                name: data
            }
        }).then(res => {
            if (res.data.ok === 1) {
                commit('setUserVideoData', res.data.data)
            }
        }).catch(err => {
            console.log("错误提示：" + err);
        });
    },


    // 设置skillCol的数据，新建技术文章的文件夹
    async setSkillCol({ commit }, data) {
        return await axios.get(`${userUrl}/userdata/setSkillCol`, {
            params: data,
            paramsSerializer: params => {
                return qs.stringify(params, { indices: false });
            }
        })
    },

    // 获取到技术文章的所有文件夹
    getSkillCol({ commit }, data) {
        axios.get(`${userUrl}/userdata/getSkillCol`, {
            params: {
                userName: data
            }
        }).then(res => {
            commit("setSkillColData", res.data.data)
        }).catch(err => {
            console.log("错误提示：" + err);
        });
    },


    // 获取当前的页面中的用户的文章集合
    async getAllSkillCol({ commit }, data) {
        return await axios.get(`${userUrl}/userdata/getSkillCol`, {
            params: {
                userName: data
            }
        })
    },




    async setSkillData({ commit }, data) {
        let tags = data.skillForm.tags.split(/,|，/)

        return await axios.post(`${userUrl}/userdata/setSkillData`, {
            params: {
                userName: data.userName,
                name: data.skillForm.name,
                tags: tags,
                label: data.skillForm.label,
                hot: data.skillForm.hot,
                body: data.skillForm.body,
                type: data.skillForm.type
            },
            paramsSerializer: params => {
                return qs.stringify(params, { indices: false });
            }
        })
    },

    getSkillData({ commit }, data) {
        axios.get(`${userUrl}/userdata/getskilldata`, {
            params: {
                userName: data
            }
        }).then(res => {
            if (res.data.ok === 1) {
                commit("setSkillData", res.data.data)
            }
        }).catch(err => {
            console.log("错误信息" + err);
        })
    },



    // 获取个人宣言
    async getDeclarationData({ commit }, data) {
        return await axios.get(`${userUrl}/userdata/getdeclarationData`, {
            params: {
                userName: data
            }
        })
    },


    async setDeclarationData({ commit }, data) {
        return await axios.get(`${userUrl}/userdata/setdeclarationData`, {
            params: data
        })
    },


    getAllZymData({ commit }, data) {
        axios.get(`${userUrl}/alldata/getdeclarationData`).then(res => {
            if (res.data.ok === 1) {
                commit('setAllZymData', res.data.data)
            }
        }).catch(err => {
            console.log("错误信息：" + err);
        })
    },



    async getAllUserData({ commit }, data) {
        // 首页获取所有用户信息的前3名
        return await axios.get(`${userUrl}/alldata/getalluserdata`, {
            params: data
        })
    },


    async toggleCoverUrl({ commit }, data) {
        return await axios.post(`${userUrl}/userdata/togglecover`, data)
    },


    async setQd({ commit }, data) {
        return await axios.get(`${userUrl}/alldata/setqd`, {
            params: data
        })
    },


    getQd({ commit }, data) {
        axios.get(`${userUrl}/alldata/getqd`, {
            params: data
        }).then(res => {
            commit('setQdNumber', res.data.data)
        }).catch(err => {
            console.log("错误信息：" + err);
        })
    },


    async initQdStore({ commit }, data) {
        return await axios.get(`${userUrl}/alldata/getqdstore`, {
            params: data
        })
    },



    async setNoteBookData({ commit }, data) {
        return await axios.get(`${userUrl}/alldata/setnotebook`, {
            params: data
        })
    },


    getNoteBookData({ commit }, data) {
        axios.get(`${userUrl}/alldata/getnotebook`, {
            params: data
        }).then(res => {
            commit('setAllNoteBook', res.data.data)
        })
    },

    async toggleNoteBookStatus({ commit }, data) {
        return await axios.get(`${userUrl}/alldata/togglenotebookstatus`, {
            params: data
        })
    },

    async delectNoteBookData({ commit }, data) {
        return await axios.get(`${userUrl}/alldata/delectnotebookdata`, {
            params: data
        })
    },



    // 获取相对应的技术文章数据
    async getAllSkillData({ commit }, data) {
        axios.get(`${userUrl}/alldata/getallskilldata`, {
            params: data
        }).then(res => {
            if (res.data.ok === 1) {


                commit('setAllSkillData', res.data.data)
            }
        })
    },



    async sendMessageToUser({ commit }, data) {
        return await axios.get(`${userUrl}/alldata/sendmessagetouser`, {
            params: data
        })
    },


    getMessage({ commit, state }, data) {
        axios.get(`${userUrl}/alldata/getMessage`, {
            params: data
        }).then(res => {
            if (res.data.ok === 1) {
                let userMessage = state.userMessage;
                let resData = res.data.data;
                if (userMessage) {
                    if (userMessage.length === resData.length) {
                        let status1 = 0, status2 = 0;
                        for (let i = 0; i < userMessage.length; i++) {
                            if (userMessage[i].status) {
                                status1++
                            }
                        }
                        for (let i = 0; i < resData.length; i++) {
                            if (resData[i].status) {
                                status2++
                            }
                        }
                        if (status1 === status2) {
                            return
                        } else {
                            commit('setMessage', res.data.data)
                        }
                    } else {
                        commit('setMessage', res.data.data)
                    }
                } else {
                    commit('setMessage', res.data.data)
                }
            }
        })
    },


    async sendUserNameMessage({ commit }, data) {
        return await axios.get(`${userUrl}/userdata/getuserdata`, {
            params: data
        })
    }
    ,


    async toggleMessageStatus({ commit }, data) {
        return await axios.get(`${userUrl}/alldata/togglemessagestatus`, {
            params: data
        })
    },

    async getOneToOneMessage({ commit }, data) {
        return await axios.get(`${userUrl}/alldata/getonetoonemessage`, {
            params: data
        })
    },

    async setSkillCommentData({ commit }, data) {



        return await axios.get(`${userUrl}/alldata/setskillcommentdata`, {
            params: data
        })
    },

    getSkillCommentData({ commit }, data) {
        axios.get(`${userUrl}/alldata/getSkillCommentData`, {
            params: data
        }).then(res => {
            if (res.data.ok === 1) {
                commit("setSkillCommentData", res.data.data)
            }
        })
    },


    async setCommentChildrenData({ commit }, data) {



        return await axios.get(`${userUrl}/alldata/setcommentchildrendata`, {
            params: data
        })
    },

    async getSkillInId({ commit }, data) {
        // 通过_id获取到skill的数据
        return await axios.get(`${userUrl}/alldata/getskillinid`, {
            params: data
        })
    },


    async getIdRzInUser({ commit }, data) {
        return await axios.get(`${userUrl}/alldata/getidrzinuser`, {
            params: data
        })
    },




    async setRzCommentData({ commit }, data) {
        return await axios.get(`${userUrl}/alldata/setrzcomment`, {
            params: data
        })
    },



    async setRzChildCommentData(ctx, data) {
        return await axios.get(`${userUrl}/alldata/setrzchildcomment`, {
            params: data
        })
    },


    async setStar(ctx, data) {
        return await axios.get(`${userUrl}/alldata/setstar`, {
            params: data
        })
    },

    async getSkillStar(ctx, data) {
        return await axios.get(`${userUrl}/alldata/getstar`, {
            params: data
        })
    },

    async lookUserInfo(ctx, data) {
        return await axios.get(`${userUrl}/alldata/lookuserinfo`, {
            params: data
        })
    },


    async getRecommendSkill(ctx, data) {
        return await axios.get(`${userUrl}/alldata/getrecommendskill`, {
            params: data
        })
    },



    async  getUserInfoInSkill({ commit }, userName) {
        return await axios.get(`${userUrl}/userdata/getuserdata`, {
            params: {
                userName: userName
            }
        })
    },


    getBannerData({ commit }) {
        axios.get(`${userUrl}/alldata/getbannerData`).then(res => {

            if (res.data.ok === 1) {


                commit('setBannerData', res.data.data)
            } else {
                commit('setBannerData', [])
            }
        })
    },


    async setSkillWatchData({ commit }, data) {
        return await axios.get(`${userUrl}/alldata/setskillwatchdata`, {
            params: data
        })
    },


    async setUserDataState(ctx, data) {
        return await axios.get(`${userUrl}/alldata/setuserdatastate`, {
            params: data
        })
    },


    async getAllAlbumsData(ctx, data) {
        return await axios.get(`${userUrl}/alldata/getallalbumsdata`)
    },


    async getThisPhotos(ctx, data) {
        return await axios.get(`${userUrl}/alldata/getthisphotos`, {
            params: data
        })
    },

    async getLookupInAlbums(ctx, data) {
        return await axios.get(`${userUrl}/alldata/getlookupinalbums`, {
            params: data
        })
    },


    async getAllVideosData(ctx, data) {
        return await axios.get(`${userUrl}/alldata/getallvideosdata`)
    },



    async getUserInfoInVideos(ctx, data) {
        return await axios.get(`${userUrl}/alldata/getuserinfoinvideos`, {
            params: data
        })
    },

    async getVideoInVideos(ctx, data) {
        return await axios.get(`${userUrl}/alldata/getvideoinvideos`, {
            params: data
        })
    },


    async getThisVideoData(ctx, data) {
        // 单个视频播放的页面需要获取的数据
        return await axios.get(`${userUrl}/alldata/getthisvideodata`, {
            params: data
        })
    },


    async setVideoCommentData(ctx, data) {
        return await axios.get(`${userUrl}/alldata/setvideocommentdata`, {
            params: data
        })
    },


    async getThisVideoCommentData(ctx, data) {
        return await axios.get(`${userUrl}/alldata/getthisvideocommentdata`, {
            params: data
        })
    },

    async setVideoChildCommentData(ctx, data) {
        return await axios.get(`${userUrl}/alldata/setvideochildcommentdata`, {
            params: data
        })
    },




    async getNavData(ctx, data) {
        return await axios.get(`${userUrl}/alldata/getnavdata`)
    },

    async setNavData(ctx, data) {
        return await axios.get(`${userUrl}/alldata/setnavdata`, {
            params: data
        })
    },


    async addNavClassData(ctx, data) {
        return await axios.get(`${userUrl}/alldata/addnavclassdata`, {
            params: data
        })
    },


    async setResourceData(ctx, data) {
        return await axios.post(`${userUrl}/alldata/setresourcedata`, data)
    },


    async getAllResourceData(ctx, data) {
        return await axios.get(`${userUrl}/alldata/getallresourcedata`, {
            params: data
        })
    },



    async getUploadData(ctx, data) {
        return await axios.get(`${userUrl}/alldata/getuploaddata`, {
            params: data
        })
    },

    async setResourceCommentData(ctx, data) {
        return await axios.get(`${userUrl}/alldata/setResourceCommentData`, {
            params: data
        })
    },


    async getResourceAllCommentData(ctx, data) {
        return await axios.get(`${userUrl}/alldata/getResourceAllCommentData`, {
            params: data
        })
    },

    async setResourceChildCommentData(ctx, data) {
        return await axios.get(`${userUrl}/alldata/setResourceChildCommentData`, {
            params: data
        })
    },



    async getAllResourcesData(ctx, data) {
        return await axios.get(`${userUrl}/alldata/getallresourcesData`, {
            params: data
        })
    },


    async addThisWatchNumber(ctx, data) {
        return await axios.get(`${userUrl}/allData/addThisWatchNumber`, {
            params: data
        })
    },


    async delIntegral(ctx, data) {
        return await axios.get(`${userUrl}/allData/delIntegral`, {
            params: data
        })
    },


    async addThisUploadNumber(ctx, data) {
        return await axios.get(`${userUrl}/allData/addThisUploadNumber`, {
            params: data
        })
    }











}


